package com.j283_5.wisdom_park.controller.maintenance_record;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.j283_5.wisdom_park.common.result.ResultData;
import com.j283_5.wisdom_park.service.MaintenanceRecordService;
import com.j283_5.wisdom_park.vo.maintenance_management.MaintenanceVo;
import com.j283_5.wisdom_park.vo.warning_management.WarningDeliveryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Param;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author laoda
 * @since 2022-04-28
 */
@Transactional
@RestController
@RequestMapping("/maintenance")
@Api(value = "运维记录管理",tags = "运维记录管理",produces="王银伟")
public class MaintenanceRecordController {

    @Resource
    private MaintenanceRecordService maintenanceRecordService;

    @RequestMapping(value = "/maintenanceRecord" , method = RequestMethod.POST)
    @ApiOperation(value = "查询所有运维信息",notes = "查询所有运维信息（分页）",produces="王银伟", response = ResultData.class)
    public ResultData maintenanceRecordList(@Param("page") Page<MaintenanceVo> page, @Param("maintenanceVo") MaintenanceVo maintenanceVo){
        //将需要模糊查询的条件存储到map中
        Map<String,Object> map = new HashMap();

        List<MaintenanceVo> maintenanceVoList = maintenanceRecordService.queryAllMaintenance(page, maintenanceVo,0);

        if (!(maintenanceVoList != null && maintenanceVoList.size() > 0)){
            return ResultData.error();
        }

        Integer sum = maintenanceRecordService.queryMaintenanceCount(maintenanceVo,0);
        map.put("maintenanceVoList",maintenanceVoList);
        map.put("sum",sum);

        return ResultData.ok().data(map);
    }

    @RequestMapping(value = "/maintenanceDelete" , method = RequestMethod.POST)
    @ApiOperation(value = "删除运维信息",notes = "删除运维信息以及批量删除",produces="王银伟", response = ResultData.class)
    public ResultData maintenanceDelete(@RequestBody ArrayList<Integer> mrecIdList){
        if (maintenanceRecordService.deleteMaintenance(mrecIdList)){
            return ResultData.ok().data("删除成功");
        }
        return ResultData.error().message("删除失败");
    }

    @RequestMapping(value = "/maintenanceDelivery" , method = RequestMethod.POST)
    @ApiOperation(value = "查询运维记录详情信息",notes = "查询运维记录详情信息",produces="王银伟", response = ResultData.class)
    public ResultData warningDelivery(Integer mrecId){
        return ResultData.ok().data(maintenanceRecordService.queryMaintenanceDelivery(mrecId));
    }


    @RequestMapping(value = "/maintenanceDeliveryUpload" , method = RequestMethod.POST)
    @ApiOperation(value = "派送运维信息",notes = "派送运维信息",produces="王银伟", response = ResultData.class)
    public ResultData warningDeliveryUpload(Integer mrecId,Integer adminId){
        if (maintenanceRecordService.maintenanceDelivery(mrecId, adminId)){
            return ResultData.ok().data("派送成功");
        }
        return ResultData.error().message("派送失败");
    }

}

